package com.zhongyouyun.utils;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongyouyun.other.model.PageRequest;
import org.omg.CORBA.Object;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class QueryUtils {

    public static void fiterQuery(QueryWrapper queryWrapper, PageRequest pageRequest) {
        pageRequest.getColumnFilters().forEach((k, v) -> {
            Map map = (Map) v;
            String eq = (String) map.get("eq");
            if ("%".equals(eq) && ObjectUtil.isNotEmpty(map.get("value"))) {
                queryWrapper.like(StrUtil.toUnderlineCase(k), map.get("value"));
            }else if("!%".equals(eq) && ObjectUtil.isNotEmpty(map.get("value"))){
                queryWrapper.notLike(StrUtil.toUnderlineCase(k), map.get("value"));
            }else if("=".equals(eq) && ObjectUtil.isNotEmpty(map.get("value"))){
                queryWrapper.eq(StrUtil.toUnderlineCase(k), map.get("value"));
            }else if("!=".equals(eq) && ObjectUtil.isNotEmpty(map.get("value"))){
                queryWrapper.ge(StrUtil.toUnderlineCase(k), map.get("value"));
            }
        });
    }
}
